package member.base.service;

import m.common.model.util.QueryCondition;
import m.common.service.Service;
import m.system.exception.MException;
import member.base.model.StatusModel;
import member.base.model.UserInfo;

import java.sql.SQLException;

public class UserInfoService extends Service {
    public UserInfo getUserByLogin(String phoneNum,String passwordMd5) throws SQLException, MException {
        UserInfo user=getModel(UserInfo.class,new String[]{"*"},
            QueryCondition.and(
                QueryCondition.eq("phoneNum",phoneNum),
                QueryCondition.eq("password",passwordMd5)
            )
        );
        if(null==user) throw new MException("手机号或密码错误");
        if(!StatusModel.StatusEnabled.equals(user.getStatus())){
            throw new MException("用户已停用");
        }
        return user;
    }
    public String getUserOidByToken(String token) throws SQLException, MException {
        UserInfo user=getModel(UserInfo.class,new String[]{"oid"},
            QueryCondition.and(
                QueryCondition.eq("token",token),
                QueryCondition.eq("status",StatusModel.StatusEnabled)
            )
        );
        if(null!=user) return user.getOid();
        else return null;
    }
}
